﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GcmpUiBase.h"
#include "WeakReferenceable.h"
#include "WeakPtr.h"
#include <QtCore/QObject>

class QTimerEvent;
namespace gcmp {
    
    class Trash;
    class TrashBin;

    class GCMP_UIBASE_EXPORT ITrashBinHandler : public gcmp::WeakReferenceable
    {
    public:
        virtual ~ITrashBinHandler();
        virtual bool onAllowToClear(const TrashBin *) const = 0;
    };

    class TrashBin : public QObject
    {   
    public:
        GCMP_UIBASE_EXPORT TrashBin(ITrashBinHandler * pHandler);
        GCMP_UIBASE_EXPORT ~TrashBin();

        GCMP_UIBASE_EXPORT static TrashBin * get();
        
         bool discard(Trash *);

        GCMP_UIBASE_EXPORT void clearExplicitly() { clear(); }
        
    protected:
        virtual void timerEvent(QTimerEvent *) override;
        
    private:
        bool clear();
    
        std::list< gcmp::OwnerPtr< Trash > > m_list;
        int m_timerId;

        gcmp::WeakPtr< ITrashBinHandler > m_wpHandler;
    };

}
